package cn.com.taurus.controller.datatable;

import cn.com.taurus.biz.AdminLogBiz;
import cn.com.taurus.biz.SystemNoticeBiz;
import cn.com.taurus.entity.AdminLog;
import cn.com.taurus.entity.SystemNotice;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;

/**
 * @author zjw
 * @createTime 2021年6月28日
 * @remark 日志控制层
 * @version 1.0
 */
@Controller
public class AdminLogController {
    @Autowired
    private AdminLogBiz adminLogBiz;

    @RequestMapping("/adminLog")
    public String systemNotice() {
        return "datatable/adminLog";
    }


    @RequestMapping("/deleteAdminLog")
    public String deleteSystemNotice(){
        adminLogBiz.deleteAllAdminLog();
        return "datatable/adminLog";
    }

    /**
     * 模糊查询
     * @param pageNum 几条
     * @param pageSize 数量
     * @return
     */
    @ResponseBody
    @RequestMapping("/selectDimAdminLog")
    public HashMap selectDimAdminLog(Integer pageNum, Integer pageSize,AdminLog adminLog){
        System.out.println("11111111");
        HashMap<String, Object> map = new HashMap<>();
        // 开启分页支持
        PageHelper.startPage(pageNum,pageSize);
        List<AdminLog> rule = adminLogBiz.selectDimAdminLog(adminLog);
        System.out.println(adminLog);
        PageInfo<AdminLog> pageInfo = new PageInfo<>(rule);

        map.put("code",0);
        map.put("msg","请求成功");
        //count：总数据条数
        map.put("count",pageInfo.getTotal());
        //data：数据
        map.put("data",pageInfo.getList());

        return map;
    }

    /**
     * 分页
     * @param pageNum
     * @param pageSize
     * @return
     */
    @ResponseBody
    @RequestMapping("/selectAdminLog")
    public HashMap selectAdminLog(Integer pageNum,Integer pageSize){
        HashMap<String, Object> map = new HashMap<>();
        // 开启分页支持
        PageHelper.startPage(pageNum,pageSize);
        List<AdminLog> rule = adminLogBiz.queryAllAdminLog();
        PageInfo<AdminLog> pageInfo = new PageInfo<>(rule);

        map.put("code",0);
        map.put("msg","请求成功");
        //count：总数据条数
        map.put("count",pageInfo.getTotal());
        //data：数据
        map.put("data",pageInfo.getList());

        return map;
    }
}
